package com.example.base;

import com.example.module.User;

public class DemoContext {

    private static final ThreadLocal<String> phoneThreadLocal = new ThreadLocal<>();

    private static final ThreadLocal<String> tokenThreadLocal = new ThreadLocal<>();

    private static final ThreadLocal<User> LOGIN_USER_INFO = new ThreadLocal<>();

    private static void setUser(User user){
        LOGIN_USER_INFO.set(user);
    }

    private static User getUserInfo(){
        return LOGIN_USER_INFO.get();
    }

    public static void setPhone(String phone){
        phoneThreadLocal.set(phone);
    }

    public static String getPhone(){
        return phoneThreadLocal.get();
    }

    public static void setToken(String token){
        tokenThreadLocal.set(token);
    }

    public static String getToken(){
        return tokenThreadLocal.get();
    }

    public static void clearToken(){
        System.out.println("当前线程名称："+Thread.currentThread().getName());
        tokenThreadLocal.remove();
    }

    public static void clearPhone(){
        System.out.println("当前线程名称："+Thread.currentThread().getName());
        phoneThreadLocal.remove();
    }

    public static void clearUser(){
        LOGIN_USER_INFO.remove();
    }


}
